import java.sql.*;

public class DataRet {

	public static void main(String[] args) throws SQLException
	{
		
		Connection conn=null;
		
		
        try
        {
            
            Class.forName ("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection ("jdbc:mysql://csdb.csc.villanova.edu/auppalap", "auppalap", "fL00355727");
            System.out.println ("Database connection established");
            Statement s=conn.createStatement();
            s.executeQuery("select * from Users");
     	    ResultSet rs = s.getResultSet ();
     	    System.out.println("Before While");
     	   while(rs.next())
     	   {
     		   System.out.println("Inner While");
     	       String usname= rs.getString("uname");
     	       String pass= rs.getString("pwd");
     	       System.out.println ("Username is "+usname+" Password is "+pass);
     	               }
        }
        catch (Exception e)
        {
            System.out.println ("Cannot connect to database server" + e);

        }
        finally
        {
            if (conn != null)
            {
                try
                {
                	 
                    conn.close ();
                    System.out.println ("Database connection terminated");
                }
                catch (Exception e) { /* ignore close errors */ }
            }
        }
	}
}

